#pragma once

#include "TypeInfo.h"
#include "Helpers.h"

namespace MockItNow
{
	class ExceptionRecordInterface
	{
	public:

		virtual ~ExceptionRecordInterface()
		{
		}

		virtual std::string GetTypeName() const = 0;
		virtual void ThrowValueAsException() const = 0;
	};

	template<typename T>
	class ExceptionRecord : public ExceptionRecordInterface
	{
	public:
	
		typedef typename TypeInfo<T>::StorageType ExceptionType;

		ExceptionRecord()
		: m_exceptionValue(0)
		{
		}

		virtual ~ExceptionRecord()
		{
			delete m_exceptionValue;
		}

		virtual std::string GetTypeName() const
		{
			return GetFriendlyTypeName<T>();
		}

		virtual void ThrowValueAsException() const
		{
			throw *m_exceptionValue;
		}

		void SetException(ExceptionType const & exceptionValue)
		{
			m_exceptionValue = new ExceptionType(exceptionValue);
		}
	
		ExceptionType& GetException() const
		{
			MOCKITNOW_ASSERT(m_exceptionValue != 0);
			return *m_exceptionValue;
		}

	private:

		ExceptionType* m_exceptionValue;
	};
}
